//============================================================================
// Name        : Deck.cpp
// Author      : awhuck
// Version     :
//============================================================================

#include "card/deck.h"
#include <vector>
#include <time.h>

///Constructor
Deck::Deck()
{
	srand( time(NULL) );
}

Deck::~Deck()
{
	for( int i = 0; i < (int)cards.size(); i++ )
	{
		delete cards[i];
	}
	
	cards.clear();
}

//Adds one card to the deck
void Deck::Add(CardInfo* card)
{
	cards.insert(cards.begin(), card);
}

//Removes the top card from the deck
CardInfo* Deck::Remove()
{
	CardInfo* info = cards.back();
	cards.pop_back();
	return info;
}

//Adds many cards to the deck
void Deck::Add(vector<CardInfo*> cards)
{
	this->cards = cards;
}

//Removes all cards form the deck
void Deck::RemoveAll()
{
	for( int i = 0; i < (int)cards.size(); i++ )
	{
		delete cards[i];
	}
	
	cards.clear();
}

//Shuffles the deck
void Deck::Shuffle()
{
	vector<CardInfo*> temp = cards;
	cards.clear();
	
	int pos;
	while( temp.size() > 0 )
	{
		pos = rand() % temp.size();
		cards.push_back(temp[pos]);
		temp.erase(temp.begin() + pos);
	}
}
